package com.ruoyi.dict.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.dict.mapper.TDictReportTypeMapper;
import com.ruoyi.dict.domain.TDictReportType;
import com.ruoyi.dict.service.ITDictReportTypeService;
import com.ruoyi.dict.service.IDictUsageCheckService;
import com.ruoyi.common.exception.ServiceException;

/**
 * 报修类型Service业务层处�?
 * 
 * @author ruoyi
 * @date 2025-09-24
 */
@Service
public class TDictReportTypeServiceImpl implements ITDictReportTypeService 
{
    @Autowired
    private TDictReportTypeMapper tDictReportTypeMapper;
    
    @Autowired
    private IDictUsageCheckService dictUsageCheckService;

    /**
     * 查询报修类型
     * 
     * @param code 报修类型主键
     * @return 报修类型
     */
    @Override
    public TDictReportType selectTDictReportTypeByCode(String code)
    {
        return tDictReportTypeMapper.selectTDictReportTypeByCode(code);
    }

    /**
     * 查询报修类型列表
     * 
     * @param tDictReportType 报修类型
     * @return 报修类型
     */
    @Override
    public List<TDictReportType> selectTDictReportTypeList(TDictReportType tDictReportType)
    {
        return tDictReportTypeMapper.selectTDictReportTypeList(tDictReportType);
    }

    /**
     * 新增报修类型
     * 
     * @param tDictReportType 报修类型
     * @return 结果
     */
    @Override
    public int insertTDictReportType(TDictReportType tDictReportType)
    {
        return tDictReportTypeMapper.insertTDictReportType(tDictReportType);
    }

    /**
     * 修改报修类型
     * 
     * @param tDictReportType 报修类型
     * @return 结果
     */
    @Override
    public int updateTDictReportType(TDictReportType tDictReportType)
    {
        return tDictReportTypeMapper.updateTDictReportType(tDictReportType);
    }

    /**
     * 批量删除报修类型
     * 
     * @param codes 需要删除的报修类型主键
     * @return 结果
     */
    @Override
    public int deleteTDictReportTypeByCodes(String[] codes)
    {
        // 检查每个报修类型是否被使用
        for (String code : codes) {
            if (dictUsageCheckService.isReportTypeInUse(code)) {
                String description = dictUsageCheckService.getReportTypeUsageDescription(code);
                throw new ServiceException(description);
            }
        }
        return tDictReportTypeMapper.deleteTDictReportTypeByCodes(codes);
    }

    /**
     * 删除报修类型信息
     * 
     * @param code 报修类型主键
     * @return 结果
     */
    @Override
    public int deleteTDictReportTypeByCode(String code)
    {
        // 检查报修类型是否被使用
        if (dictUsageCheckService.isReportTypeInUse(code)) {
            String description = dictUsageCheckService.getReportTypeUsageDescription(code);
            throw new ServiceException(description);
        }
        return tDictReportTypeMapper.deleteTDictReportTypeByCode(code);
    }
}
